--  --------------------------------------------------------------------------
--  @Main:        html_writer.adb
--
--  @Project:     HTML_writer
--  @Version:     1,0
--  @Created:     2011-11-22
--  @Description: Creates a HTML index file.
--
--  @Author:  Benedikt Markt, Aleksander Zotov, Marcel Kranz,
--  --------------------------------------------------------------------------

with Ada.Text_IO, Ada.Strings.Fixed, Ada.Strings;
use  Ada.Text_IO;

--  --------------------------------------------------------------------------
--  @Procedure HTML_Writer
procedure HTML_Writer is

   HTML_File : Ada.Text_IO.File_Type;

   --  -----------------------------------------------------------------------
   --  @Procedure: Start_Page
   --
   --  @Description: Add <html> tag to the file
   --  @Parameter:
   --    +File: The file to edit.
   procedure Start_Page (File : in File_Type) is
   begin
      Ada.Text_IO.Put_Line (File, "<html>");
   end Start_Page;

   --  -----------------------------------------------------------------------
   --  @Procedure: Finish_Page
   --
   --  @Description: Add  </html> tag to end the file.
   --  @Parameter:
   --    +File: The file to edit.
   procedure Finish_Page (File : in File_Type) is
   begin
      Ada.Text_IO.Put_Line (File, "</html>");
   end Finish_Page;

   --  -----------------------------------------------------------------------
   --  @Procedure: Write_Head
   --
   --  @Description: Creates and order the header of the html document.
   --  @Parameter:
   --    +File: The file to edit.
   --    +Title The title of the html document.
   procedure Write_Head (File : in File_Type; Title : in String) is
   begin
      Ada.Text_IO.Put (File, "<head><title>");
      Ada.Text_IO.Put (File, Title);
      Ada.Text_IO.Put_Line (File, "</title></head>");
   end Write_Head;

   --  -----------------------------------------------------------------------
   --  @Procedure: Start_Body
   --
   --  @Description: Body of the html page is implemented.
   --  @Parameter:
   --    +File: The file to edit.
   procedure Start_Body (File : in File_Type) is
   begin
      Ada.Text_IO.Put_Line (File, "<body>");
   end Start_Body;

   --  -----------------------------------------------------------------------
   --  @Procedure: Finish_Body
   --
   --  @Description: Close a </body> tag.
   --  @Parameter:
   --    +File: The file to edit.
   procedure Finish_Body (File : in File_Type) is
   begin
      Ada.Text_IO.Put_Line (File, "</body>");
   end Finish_Body;

   --  -----------------------------------------------------------------------
   --  @Procedure: Write_Heading
   --
   --  @Description: Writes the headlines with given level to the html file.
   --  @Parameter:
   --    +File: The file to edit.
   --    +Text: The text of the heading.
   --    +Level: The level of the heading.
   procedure Write_Heading
     (File  : in File_Type;
      Text  : in String;
      Level : in Positive) is
   begin
      Ada.Text_IO.Put (File, "<h");
      Ada.Text_IO.Put
        (File,
         Ada.Strings.Fixed.Trim (Positive'Image (Level), Ada.Strings.Both));
      Ada.Text_IO.Put (File, ">");
      Ada.Text_IO.Put (File, Text);
      Ada.Text_IO.Put (File, "</h");
      Ada.Text_IO.Put
        (File,
         Ada.Strings.Fixed.Trim (Positive'Image (Level), Ada.Strings.Both));
      Ada.Text_IO.Put_Line (File, ">");
   end Write_Heading;

   --  -----------------------------------------------------------------------
   --  @Procedure: Add_Paragraph
   --
   --  @Description: Adds a line by writing to the page.
   --  @Parameter:
   --    +File: The file to edit.
   --    +Text: The text to add to the file.
   procedure Add_Paragraph (File : in File_Type; Text : in String) is
   begin
      Ada.Text_IO.Put (File, "<p>");
      Ada.Text_IO.Put (File, Text);
      Ada.Text_IO.Put (File, "</p>");
   end Add_Paragraph;

   --  -----------------------------------------------------------------------
   --  @Procedure: Start_List
   --
   --  @Description: Start an unordered list by writing a <ul> tag.
   --  @Parameter:
   --    +File: The file to edit.
   procedure Start_List (File : in File_Type) is
   begin
      Ada.Text_IO.Put (File, "<ul>");
   end Start_List;

   --  -----------------------------------------------------------------------
   --  @Procedure: Finish_List
   --
   --  @Description: Finish an unordered list by writing </ul> tag.
   --  @Parameter:
   --    +File: The file to edit.
   procedure Finish_List (File : in File_Type) is
   begin
      Ada.Text_IO.Put (File, "</ul>");
   end Finish_List;

   --  -----------------------------------------------------------------------
   --  @Procedure: Start_List_Item
   --
   --  @Description: Start a new list item by writing <li>.
   --  @Parameter:
   --    +File: The file to edit.
   procedure Start_List_Item (File : in File_Type) is
   begin
      Ada.Text_IO.Put (File, "<li>");
   end Start_List_Item;

   --  -----------------------------------------------------------------------
   --  @Procedure: Finish_List_Item
   --
   --  @Description: Finish a list item by writing </li>.
   --  @Parameter:
   --    +File: The file to edit.
   procedure Finish_List_Item (File : in File_Type) is
   begin
      Ada.Text_IO.Put (File, "</li>");
   end Finish_List_Item;

   --  -----------------------------------------------------------------------
   --  @Procedure: Add_Link
   --
   --  @Description: Adds a link.
   --  @Parameter:
   --    +File: The file to edit.
   --    +Target: Target of the link.
   --    +Text: Link text
   procedure Add_Link
     (File   : in File_Type;
      Target : in String;
      Text   : in String) is
   begin
      Ada.Text_IO.Put (File, "<a href =""");
      Ada.Text_IO.Put (File, Target);
      Ada.Text_IO.Put (File, """>");
      Ada.Text_IO.Put (File, Text);
      Ada.Text_IO.Put (File, "</a>");
   end Add_Link;

   --  -----------------------------------------------------------------------
   --  @Procedure: Add_Text
   --
   --  @Description: Add text  to the HTML document.
   --  @Parameter:
   --    +File: The file to edit.
   --    +Text: The text to add to rhe file
   procedure Add_Text (File : in File_Type; Text : in String) is
   begin
      Ada.Text_IO.Put (File, Text);
   end Add_Text;

begin

   Ada.Text_IO.Create (HTML_File, Out_File, "hello.html");
   Start_Page (HTML_File);
   Write_Head (HTML_File, "Hello HTML");
   Start_Body (HTML_File);
   Write_Heading (HTML_File, "Hello HTML", 1);
   Add_Paragraph (HTML_File, "Possibly, this is my first HTML file!");
   Start_List (HTML_File);
   Start_List_Item (HTML_File);
   Add_Text (HTML_File, "First list item");
   Finish_List_Item (HTML_File);
   Start_List_Item (HTML_File);
   Add_Text (HTML_File, "Second list item");
   Finish_List_Item (HTML_File);
   Start_List_Item (HTML_File);
   Add_Text (HTML_File, "Third list item");
   Finish_List_Item (HTML_File);
   Finish_List (HTML_File);
   Finish_Body (HTML_File);
   Finish_Page (HTML_File);
   Ada.Text_IO.Close (HTML_File);
end HTML_Writer;
